'''
Created on 22/dic/2010

@author: rbutti
'''
from google.appengine.ext import db
from models import schema

class BoPlaylist(object):
    '''
    classdocs
    '''


    def __init__(selfparams):
        '''
        Constructor
        '''
        
    def loadUserPlaylist(self, user):
        query = db.GqlQuery("SELECT * FROM Playlist WHERE user = :1 ",
                    user)
        return query
    
    def addSongForUser(self, playlist, videoid, user):
        if videoid:
            #print videoId
            query = db.GqlQuery("SELECT * FROM Playlist WHERE user = :1 AND title = :2 ",user, playlist)
            quanteplaylist= query.count(1)
            if (quanteplaylist == 0):
                playlistObj = schema.Playlist(
                                                title=playlist,
                                                user=user
                                            )
                playlistObj.put()
            else:
                playlistObj = query.get()
            result={}
            song = schema.Song(
                                title="videoid",
                                video=videoid,
                                playlist=playlistObj
                            )
            song.put()
            return True
        else:
            return False
